﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CatalogHtmlContent.ascx.cs" Inherits="Shop.Web.Controls.Ajax.CatalogHtmlContent" %>
<asp:PlaceHolder runat="server" ID="phEditable">
 <script type="text/javascript">
                $(document).ready(
	            function() {
                $('.editable').editable({
	                    onSubmit:function(content){
                                    $.post("AjaxHtmlContent.aspx?Content=Category", { name: content.current , id : $this.get()[0].id } );
                                } ,
	                    submit: "OK",
	                    cancel: "Отмена",
	                    style: "inherit"
	                });
	                // Dialog			
				$('#dialog').dialog({
					autoOpen: false,
					width: 600,
					buttons: {
						"Ok": function() { 
						    $(this).dialog("close"); 
						    Add();
							
						}, 
						"Cancel": function() { 
							$(this).dialog("close"); 
						} 
					}
				});
				
	            });
                function Delete(id){
                    $.post( "AjaxHtmlContent.aspx?Content=CategoryDelete", 
                            { id : id }, 
                            function(data){$('#tabs').tabs( 'load' , 1 );} 
                           );
                    
                } 
                function Add(){
                    $.post("AjaxHtmlContent.aspx?Content=CategoryAdd", { id : $('#parentId').val(), name : $('#tbAddCategory').get()[0].value },function(data){$('#tabs').tabs( 'load' , 1 );}  );
                } 
                
                function AddClick(level)
                {
                   $('#parentId').val(level);
                   $('#dialog').dialog('open');
                }
                
	            </script>
	            <input type="hidden" id="parentId"/>
</asp:PlaceHolder>
<asp:PlaceHolder runat="server" ID="phCatalogList">
<asp:Repeater runat="server" ID="rprCatalog">
    <HeaderTemplate>
    <table>
        <tr><td ><a href="#" id="dialog_link" onclick="AddClick('0')">Добавить</a></td><td></td></tr>
    </HeaderTemplate>
    <ItemTemplate>
    <tr>
        <td>
		    <input type="button" value="Удалить" onclick="Delete('<%# DataBinder.Eval(Container.DataItem, "Id")%>')"/>
		</td>
		<td>    
		<span class="editable" id='<%# DataBinder.Eval(Container.DataItem, "Id")%>'>
		    <%# DataBinder.Eval(Container.DataItem, "Name")%>
		</span>
	 </td>
    </tr>
	<tr>
	    <td >
	    >&nbsp;<a href="#" id="dialog_link" onclick="AddClick('<%# DataBinder.Eval(Container.DataItem, "Id")%>')">Добавить</a>
	    </td>
		<td></td>
    </tr>
		<asp:Repeater DataSource='<%# DataBinder.Eval(Container.DataItem, "Children")%>' runat="server" ID="rprSubMenu">
            <ItemTemplate>
                <tr>
                    <td>
                        <input type="button" value="Удалить" onclick="Delete('<%# DataBinder.Eval(Container.DataItem, "Id")%>')"/>
                    </td>
                    <td>
                        >&nbsp;<span class="editable" id='<%# DataBinder.Eval(Container.DataItem, "Id")%>'><%# DataBinder.Eval(Container, "DataItem.Name")%></span>
                    </td>
                </tr>
                <tr>
                    <td>
                        >>&nbsp;<a href="#" id="dialog_link" onclick="AddClick('<%# DataBinder.Eval(Container.DataItem, "Id")%>')">Добавить</a>
                    </td>
                    <td></td>
                </tr>
                <asp:Repeater DataSource='<%# DataBinder.Eval(Container.DataItem, "Children")%>' runat="server" ID="rprSubMenu">
                    <ItemTemplate>
                        <tr>
                            <td>
                                <input type="button" value="Удалить" onclick="Delete('<%# DataBinder.Eval(Container.DataItem, "Id")%>')"/>
                            </td>
                            <td>
                                >>&nbsp;<span class="editable" id='<%# DataBinder.Eval(Container.DataItem, "Id")%>'><%# DataBinder.Eval(Container, "DataItem.Name")%></span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                >>>&nbsp;<a href="#" id="dialog_link" onclick="AddClick('<%# DataBinder.Eval(Container.DataItem, "Id")%>')">Добавить</a>
                            </td>
                            <td></td>
                        </tr>
                        <asp:Repeater DataSource='<%# DataBinder.Eval(Container.DataItem, "Children")%>' runat="server" ID="rprSubMenu">
                            <ItemTemplate>
                                 <tr>
                                    <td>
                                        <input type="button" value="Удалить" onclick="Delete('<%# DataBinder.Eval(Container.DataItem, "Id")%>')"/>
                                    </td>
                                    <td>
                                        >>>&nbsp;<span class="editable" id='<%# DataBinder.Eval(Container.DataItem, "Id")%>'><%# DataBinder.Eval(Container, "DataItem.Name")%></span>
                                    </td>
                                    </tr>
                                    
                            </ItemTemplate>
                        </asp:Repeater>
                    </ItemTemplate>
                </asp:Repeater>
            </ItemTemplate>
        </asp:Repeater>
   
    </ItemTemplate>   
    <FooterTemplate>
    </table>    
        <div id="dialog" title="Добавить категорию">
			<p>
			    <input type="text" id="tbAddCategory" width="200"/>
			</p>
		</div>
    </FooterTemplate> 
</asp:Repeater>
<script type="text/javascript">

function GetHTML(id) {
    $('#content').html("&nbsp;");
	url = 'AjaxHtmlContent.aspx?Content=Theme&id='+id;
	$('#content').load(url);
}

$(document).ready(function() {
  <%--  GetHTML('<%=CurrentId %>');--%>
});

</script>
</asp:PlaceHolder>
